<?php 
session_start();
if(empty($_SESSION['home'])){
header('location:login.php?a=cart');
exit;
}
if(empty($_SESSION['cart'])){
header('location:shoppingcar.php');
exit;
}
include 'head.php';

//查询收货信息
$sql = "select * from ".PRE."order_receiver where user_id='{$_SESSION['home']['id']}'";
$result = mysql_query($sql);
$addlist = array();
while($row = mysql_fetch_assoc($result)){
	$addlist[] = $row;
}
$new = $_GET['a'];
?>

	

	<div id="shopcar" class="shopcar w1">
		<div class="title" ><img src="./images/shoppingtitle2.jpg"/></div>
		<!-- 统计用户信息的表单 -->
		<div>
			<div class="admin_form fl">
				<table width="500">
					<div class="user_index_title">收货信息</div>
					<!-- 如果有收货信息，则显示收货信息 -->
					<?php if(empty($addlist) || $new == 'new'):?>
					<form action="cart_action.php?a=rec" method="post">
						<tr>
							<th>收件人：</th>
							<td><input type="text" name="name" /></td>
						</tr>
						<tr>
							<th>联系电话：</th>
							<td><input type="text" name="tel" /></td>
						</tr>
						<tr>
							<th>详细地址：</th>
							<td><input type="text" name="address" /></td>
						</tr>
						<tr>
							<td colspan="2" class="submit"><input type="submit" value="添加地址" /><a href="order_inf.php">使用已有地址</a></td>
						</tr>
					</form>
					<?php else:?>
						<form action="order_action.php" method="post">
						<?php $i = 0;foreach($addlist as $val):?>
							<tr class="radio">
								<td width="5"><input type="radio" name="address" value="<?php echo $val['id']?>" <?php if($i == 0) echo 'checked';?>/><span><?php echo $val['name'].'　　'.$val['phone'].'　　'.$val['address']?></span></td>
								<td width="10"><a href="cart_action.php?a=recdel&id=<?php echo $val['id']?>">删除</a></td>
							</tr>
						<?php $i++; endforeach;?>
							<tr><td colspan="2" class="submit"><a href="order_inf.php?a=new">使用新地址</a></td></tr>
					<?php endif;?>
				</table>
			</div>
			<div class="admin_form fl trans">
				<div class="user_index_title">配送方式</div>
				<div class="pay">货到付款</div>
			</div>
			<div class="clear"></div>
		</div>
		
		
		<!-- 商品清单 -->
		<div class="mt20">
			<?php if(!empty($_SESSION['cart'])):?>
			<table cellspacing="0" cellpadding="0" width="980">
			<div class="user_index_title">商品信息</div>
				<tr class="color">
					<th width="120">商品</th>
					<th width="300">商品名</th>
					<th>单价</th>
					<th>数量</th>
					<th>小计</th>
				</tr>
				<?php foreach($_SESSION['cart'] as $key => $val):?>
					<tr class="goods">
						<td><img src="./upload/<?php echo $val['image']?>"  height="80"/></td>
						<td><?php echo $val['name']?></td>
						<td><?php echo $val['price']?></td>
						<td><span><?php echo $val['num']?>&nbsp;</span></td>
						<td>￥<?php echo number_format($val['price'] * $val['num'],2,'.',',') ?></td>
					</tr>
				<?php $total += $val['num'] * $val['price']?>
				<?php endforeach;?>
				<tr class="color count">
					<td colspan="5" style="text-align:right;"><span>应付金额：￥<?php echo number_format($total,2,'.',',') ?> </span></td>
				</tr>
				</table>
				<div class="bottom">
					<div class="right fr">
					<?php if(empty($addlist) || $new == 'new'):?>
						<a href="#"><span class="order_error">还没有选择地址</span></a>
					<?php else:?>
						<input  id="submit" type="submit" value=""/>
					<?php endif;?>
					</div>
					<div class="clear"></div>
				</div>
				
				
				<?php else:?>
					<div class="shop_empty" >购物车还没有货！亲，赶紧开心购物吧！！</div>
				<?php endif;?>
			
					</form>
		</div>
	</div>


<?php include 'footer.php';?>
